n = input()

if len(n) != 4 or not n.isdigit():
    print(0)
else:

    z = 0
    for i in range(4):
        for j in range(i + 1, 5):
            num = int(n[i:j])
            prime = True
            if num <= 1:
                prime = False
            else:
                for p in range(2, int(num ** 0.5) + 1):
                    if num % p == 0:
                        prime = False
                        break
            if prime and num > z:
                z = num
    print(z)